<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/modify.css" />
	</head>

	<body>
		<div class="title">
			<div class="mui-icon mui-icon-back back"></div>
			<div class="set">设置</div>
			<div class="right" id="baocun">
				<img src="img/right.png" alt="" />
			</div>
		</div>
		<div class="content" id="mymodify">
			<div id="modifyimg" class="title_img">
				<img id="inimage" :src="mydf.avatar" value="" alt="" style="height:100px;width: 100px;" />
			</div>
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>昵 称</label>
					<input id="username" type="text" class="mui-input-clear" v-bind:value="mydf.username">
				</div>
			</form>
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>生 日</label>
					<input type="text" class="mui-input-clear" value="2000-1-1">
				</div>
			</form>
			<form class="mui-input-group set_email">
				<div class="mui-input-row">
					<label>邮 箱</label>
					<input id="email" type="text" class="mui-input-clear" :value="mydf.email">
				</div>
			</form>
			<form class="mui-input-group set_country">
				<div class="mui-input-row">
					<label>城 市</label>
					<input type="text" class="mui-input-clear" value="保定">
				</div>
			</form>
			<textarea id="textarea" rows="5" :value="mydf.remarks" ></textarea>

		</div>
	</body>
	<script src="js/mui.min.js"></script>
	<script src="vue/vue.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/ip.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		mui.init()
		
		var my = new Vue({
			el: '#mymodify',
			data: {
				mydf: ''
			}
		});
		var BackDom = document.getElementsByClassName("back")[0];
		var InimageDom = document.getElementById("inimage");
		var NameDom = document.getElementById("username");
		var EmailDom = document.getElementById("email");
		var TextDom = document.getElementById("textarea");
		var nameD = document.querySelector('#username')
		BackDom.addEventListener("tap", function() {
			mui.back();
		});
		function callBack(){
			var index = plus.webview.getWebviewById( 'index' );
			var me = plus.webview.getWebviewById( 'me' );
			index.evalJS("ajax()");
			me.evalJS("ajax()");
		}
		mui.post("http://"+ip+"/xiaojv/Api/index.php?p=front&m=modify&a=modify", function(data) {
			if(data != null) {
				my.mydf = data[0];
			} else {
				console.log("456");
			}
		}, 'json');
		document.getElementById("baocun").addEventListener("tap", function() {
			var nname = NameDom.value
			var email = EmailDom.value;
			var ttext = TextDom.value;
			mui.post("http://"+ip+"/xiaojv/Api/index.php?p=front&m=information&a=information", {
				nname: nname,
				email: email,
				ttext: ttext
			}, function(data) {
				flag = true;
				mui.toast("修改成功");
				callBack()
			}, 'json');
		});
		var ImgDom = document.getElementById("inimage");
		ImgDom.addEventListener("tap", function() {
			//			console.log("123");
			if(mui.os.plus) {
				plus.nativeUI.actionSheet({
					title: "选择上传的头像",
					cancel: "取消",
					buttons: [{
						title: "拍照"
					}, {
						title: "从系统相册中选择"
					}]
				}, function(e) {
					var index = e.index;
					switch(index) {
						case 1:
							appendByCamera();
							break;
						case 2:
							appendByGallery();
							break;
					}
				});
			}
		});

		function appendByCamera() {
			var cmr = plus.camera.getCamera()
			cmr.captureImage(function(file) {
				plus.io.resolveLocalFileSystemURL(file, function(entry) {
					uploadImg(entry.toLocalURL());
				}, function(error) {
					var code = error.code; // 错误编码
					var message = error.message; // 错误描述信息

				});
			}, function(error) {
				var code = error.code; // 错误编码
				var message = error.message; // 错误描述信息

			}, {
				index: 1
			});
		};

		function appendByGallery() {
			plus.gallery.pick(function(file) {
				uploadImg(file);
			}, function(error) {
				var code = error.code;
				var message = error.message;

			}, {
				filter: "image"
			});
		}
		//
		function uploadImg(file) {
			var w = plus.nativeUI.showWaiting("上传中...");

			var task = plus.uploader.createUpload("http://"+ip+"/xiaojv/Api/index.php?p=front&m=modifyuploadimage&a=modifyuploadimage", {
				method: "POST"
			}, function(t, status) {
				//				var msg = JSON.parse(t.responseText);
				w.close();
				console.log(t.responseText);
				if(status == 200) {
					var obj = JSON.parse(t.responseText);
					console.log(t.responseText);
					if(obj.msg) {
						my.mydf.avatar = file;
						mui.toast("上传成功");
						flag = true;
						callBack()
					} else {
						mui.toast("上传失败");
					}
				} else {
					mui.toast("上传失败");
				}

			});

			task.addFile(file, {
				key: "img"
			});
			task.start();

		}
	</script>

</html>